package LeetCode;

public class LC_083_RemoveDuplicatesfromSortedList {
    public static void main(String[] args) {

    }

    static class Solution {
        public ListNode deleteDuplicates(ListNode head) {
            if (head == null || head.next == null)
                return head;

            ListNode prev = head;
            ListNode p = head.next;

            while (p != null) {
                if (p.val == prev.val) {
                    prev.next = p.next;
                    p = p.next;
                } else {
                    prev = p;
                    p = p.next;
                }
            }

            return head;
        }
    }

    public class Solution_2 {
        public ListNode deleteDuplicates(ListNode head) {
            if (head == null || head.next == null) return head;
            ListNode p = head;

            while (p.next != null) {
                if (p.val == p.next.val)
                    p.next = p.next.next;
                else
                    p = p.next;
            }

            return head;
        }
    }
}
